<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Partner_model extends MY_Model{
    function  __construct(){
        parent::__construct();
        $this->_table      = TBL_PARTNER;
        $this->primary_key = 'partner_id';
    }

    function get_partner($partner_id = 0, $limit = 0, $offset = 0, $orderby = NULL, $orderway = 'ASC', $active = ACTIVE_FLAG){
        $this->db->select('*')->from(TBL_PARTNER);
        $this->db->where('delete_flag', UNDELETE_FLAG);
        $this->db->where('draft', 'no');
        if ($active != ''){
            $this->db->where('active_flag', $active);
        }

        if ($partner_id != 0) {
            $this->db->where($this->primary_key, $partner_id);
            return $this->db->get()->row_array();
        } else {

            if ($limit != 0){
                if ($offset != 0) {
                    $this->db->limit($limit, $offset);
                } else {
                    $this->db->limit($limit);
                }
            }

            if ($orderby != NULL) {
                $this->db->order_by($orderby. ' '.$orderway);
            }

            return $this->db->get()->result_array();
        }
    }

    function _delete_partner($id){
        if (is_array($id) && count($id) > 0){
            $this->db->where_in($this->primary_key, $id)->update(TBL_PARTNER, array('delete_flag' => DELETE_FLAG));
            return true;
        }
        return false;
    }
}
